home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / IMAGELST.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  291 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.9  $
  6. //
  7. // Definition of class TImageList, an ImageList Common Control wrapper.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_IMAGELST_H)
  10. #define OWL_IMAGELST_H
  11.  
  12. #if !defined(OWL_GDIOBJCT_H)
  13. # include <owl/gdiobjec.h>
  14. #endif
  15. #if !defined(OWL_COMMCTRL_H)
  16. # include <owl/commctrl.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. class _OWLCLASS TImageList;
  24.  
  25. // Generic definitions/compiler options (eg. alignment) preceeding the 
  26. // definition of classes
  27. #include <services/preclass.h>
  28.  
  29. // TImageInfo is only usable in 32-bit - It requires 
  30. // 'ImageList_GetImageInfo' support
  31. //
  32. #if defined(BI_PLAT_WIN32)
  33.  
  34. //
  35. // class TImageInfo
  36. // ~~~~~ ~~~~~~~~~~
  37. // Wrapper class for a structure that describes an image within
  38. // an image list.
  39. //
  40. class _OWLCLASS TImageInfo {
  41.   public:
  42.     TImageInfo();
  43.     TImageInfo(const TImageList& list, int index = 0);
  44.  
  45.     HBITMAP GetImageBM() const;
  46.     HBITMAP GetMaskBM() const;
  47.     TRect   GetImageRect() const;  
  48.  
  49.     operator _IMAGEINFO&();
  50.  
  51.   private:
  52.     _IMAGEINFO rep;
  53.  
  54.   friend class _OWLCLASS TImageList;
  55. };
  56.  
  57. #endif  //  BI_PLAT_WIN32
  58.  
  59.  
  60. //
  61. // class TImageList
  62. // ~~~~~ ~~~~~~~~~~
  63. // Wrapper class for the ImageList common "control".
  64. //
  65. class _OWLCLASS TImageList {
  66.   public:
  67.     // Constructors
  68.     //
  69.     TImageList(const TSize& size, uint flags, int initCount, int growBy);
  70.     TImageList(const TBitmap& bmp, uint flags, int initCount, int growBy);
  71.     TImageList(const TDib& dib, uint flags, int initCount, int growBy);
  72.  
  73. #if defined(BI_PLAT_WIN32)
  74.     // 32-bit only: Requires 'ImageList_LoadImage' support
  75.     //
  76.     TImageList(HINSTANCE hI, TResId resName, int w, int growBy,
  77.                const TColor& mask, uint type, uint flags);
  78.     TImageList(const TImageList& src);
  79. #endif
  80.  
  81.     TImageList(HIMAGELIST imageList);
  82.  
  83. #if defined(BI_PLAT_WIN32)
  84.     // 32-bit only: Requires 'ImageList_GetDragImage' support
  85.     //
  86.     TImageList(TPoint& pt, TPoint& hotspot);
  87. #endif
  88.  
  89.     /*virtual*/ ~TImageList();
  90.  
  91. #if defined(BI_PLAT_WIN32)
  92.     TImageList& operator =(const TImageList&);
  93.     operator TBitmap&();
  94. #endif
  95.  
  96.     operator HIMAGELIST() const;
  97.  
  98.     // 'Get' accessors
  99.     //
  100.     int        GetImageCount() const;
  101.     TSize      GetImageSize() const;
  102.     TPoint     GetImageOffset(int cel) const;
  103.     TRect      GetImageRect(int cel) const;
  104.     TRect      operator [](int cel) const;
  105.  
  106.     // Add an image into the list
  107.     //
  108.     int        Add(const TBitmap& image);
  109.     int        Add(const TBitmap& image, const TBitmap& mask);
  110. #if defined(BI_PLAT_WIN32)
  111.     int        Add(const TBitmap& image, const TColor& mask);
  112. #endif
  113.     int        Add(const TIcon&);
  114.  
  115. #if defined(BI_PLAT_WIN32)
  116.     // Remove an image from the list
  117.     // NOTE: 32-bits only - requires support of 'ImageList_Remove'
  118.     //
  119.     bool       Remove(int index);
  120.     bool       RemoveAll();
  121. #endif
  122.  
  123. #if defined(BI_PLAT_WIN32)
  124.     // Replace the image at an index with another
  125.     //
  126.     bool       Replace(int index, const TBitmap& image);
  127.     bool       Replace(int index, const TBitmap& image, const TBitmap& mask);
  128. #endif
  129.  
  130.     // Get an icon or cursor from an image based on masks
  131.     //
  132.     int        ReplaceIcon(int index, HICON hicon);
  133. #if defined(BI_PLAT_WIN32)
  134.     HICON      GetIcon(int index, uint flags) const;
  135.     bool       GetIconSize(int& cx, int& cy);
  136. #endif
  137.  
  138. #if defined(BI_PLAT_WIN32)
  139.     bool       GetImageInfo(int index, TImageInfo& celInfo) const;
  140. #endif    
  141.  
  142.     TColor     GetBkColor() const;
  143.     TColor     SetBkColor(const TColor& newColor);
  144.  
  145.     // Draw the image
  146.     //
  147.     bool       Draw(int index, TDC&, int x, int y, uint style = ILD_NORMAL,
  148.                     int overlay = 0);
  149.  
  150. #if defined(BI_PLAT_WIN32)
  151.     // 32-bit only: requires 'ImageList_DrawEx' support
  152.     //
  153.     bool       Draw(int index, TDC&, int x, int y, int dx, int dy,
  154.                     const TColor& bgClr, const TColor& fgClr,
  155.                     uint style = ILD_NORMAL, int overlay = 0);
  156. #endif
  157.  
  158.     bool       SetOverlayImage(int index, int overlay);
  159.  
  160.     // Routines related to dragging
  161.     //
  162. #if defined(BI_PLAT_WIN32)
  163.     bool       SetDragCursorImage(int drag, int dxHotspot, int dyHotspot);
  164.     bool        BeginDrag(int index, int dxHotspot, int dyHotspot);
  165.     static bool DragEnter(HWND hwndLock,  int x, int y);
  166.     static bool DragMove(int x, int y);
  167.     static bool DragLeave(HWND hwndLock);
  168.     static void EndDrag();
  169.     static bool DragShowNolock(bool show);
  170. #endif
  171.  
  172.   protected:
  173.     void        CheckValid();
  174.  
  175.   protected_data:
  176.     HIMAGELIST  Handle;      // Handle of ImageList
  177.  
  178.   private:
  179. #if !defined(BI_PLAT_WIN32)
  180.     // Prevent accidental copy when not compiling for environment which
  181.     // supports ability to retrieve/duplicate imagelists.
  182.     //
  183.     TImageList& operator =(const TImageList&);
  184.     operator TBitmap&();
  185. #endif
  186.  
  187.     TBitmap*    Bitmap;      // Copy of image BM to work around Win95 BUG
  188.     TSize       ImageSize;   // Size of images in ImageList
  189. };
  190.  
  191. // Generic definitions/compiler options (eg. alignment) following the 
  192. // definition of classes
  193. #include <services/posclass.h>
  194.  
  195. #if defined(BI_NAMESPACE)
  196. } // namespace OWL
  197. #endif
  198.  
  199. //------------------------------------------------------------------------
  200. // Inline implementations
  201.  
  202. #if defined(BI_PLAT_WIN32)
  203.  
  204. //
  205. inline TImageInfo::TImageInfo() {
  206. }
  207.  
  208. //
  209. // Construct based on an image within the image list.
  210. //
  211. inline TImageInfo::TImageInfo(const TImageList& array, int index) {
  212.   array.GetImageInfo(index, *this);
  213. }
  214.  
  215. //
  216. // Get the image bitmap
  217. //
  218. inline HBITMAP TImageInfo::GetImageBM() const {
  219.   return rep.hbmImage;
  220. }
  221.  
  222. //
  223. // Get the image's mask
  224. //
  225. inline HBITMAP TImageInfo::GetMaskBM() const {
  226.   return rep.hbmImage;
  227. }
  228.  
  229. //
  230. // Get the area of the image
  231. //
  232. inline TRect TImageInfo::GetImageRect() const {
  233.   return rep.rcImage;
  234. }
  235.  
  236. //
  237. // Convert to an _IMAGEINFO structure
  238. //
  239. inline TImageInfo::operator _IMAGEINFO&() {
  240.   return rep;
  241. }
  242.  
  243. #endif  //  BI_PLAT_WIN32
  244.  
  245. //
  246. // Return the size each image.
  247. // Each image of the list must be the same size.
  248. //
  249. inline TSize TImageList::GetImageSize() const {
  250.   return ImageSize;
  251. }
  252.  
  253. //
  254. // Return the offset of a given image in the ImageList's bitmap
  255. //
  256. inline TPoint TImageList::GetImageOffset(int index) const {
  257.   return TPoint(index*ImageSize.cx, 0);
  258. }
  259.  
  260. //
  261. // Return the bounding rect of a given image in the ImageList's bitmap
  262. //
  263. inline TRect TImageList::GetImageRect(int index) const {
  264.   return TRect(TPoint(index*ImageSize.cx, 0), ImageSize);
  265. }
  266.  
  267. //
  268. // Return the rectangle of the image at index 'index'.
  269. //
  270. inline TRect TImageList::operator [](int index) const {
  271.   return GetImageRect(index);
  272. }
  273.  
  274. #if defined(BI_PLAT_WIN32)
  275. //
  276. // Removes all images from the list.
  277. //
  278. inline bool TImageList::RemoveAll() {
  279.   return Remove(-1);
  280. }
  281. #endif  //  BI_PLAT_WIN32
  282.  
  283. //
  284. // Convert to the HIMAGELIST structure.
  285. //
  286. inline TImageList::operator HIMAGELIST() const {
  287.   return Handle;
  288. }
  289.  
  290. #endif  // OWL_IMAGELST_H
  291.